﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using KeaoBase;

namespace KeaoDataService
{
    public partial class HunNingTu : Form
    {
        public HunNingTu()
        {
            InitializeComponent();
        }

        private DataGridViewRow m_CurrentRow;

        private void btn_shezhi_duanxin_Click(object sender, EventArgs e)
        {
            DuanXin duanXin = new DuanXin();
            duanXin.ShowDialog();
        }

        private void btn_shezhi_shuju_Click(object sender, EventArgs e)
        {
            HunNingTuSheZhi hunSheZhi = new HunNingTuSheZhi();
            hunSheZhi.ShowDialog();
        }

        private void HunNingTu_Load(object sender, EventArgs e)
        {
            dataGridView1.AutoGenerateColumns = false;

            if (KeaoUtils.ConfigGetNodeAttr("沙石料1", "状态") == "禁用")
            {
                col_shashiliao_1.Visible = false;
            }
            if (KeaoUtils.ConfigGetNodeAttr("沙石料2", "状态") == "禁用")
            {
                col_shashiliao_2.Visible = false;
            }
            if (KeaoUtils.ConfigGetNodeAttr("沙石料3", "状态") == "禁用")
            {
                col_shashiliao_3.Visible = false;
            }
            if (KeaoUtils.ConfigGetNodeAttr("沙石料4", "状态") == "禁用")
            {
                col_shashiliao_4.Visible = false;
            }
            if (KeaoUtils.ConfigGetNodeAttr("沙石料5", "状态") == "禁用")
            {
                col_shashiliao_5.Visible = false;
            }
            if (KeaoUtils.ConfigGetNodeAttr("沙石料6", "状态") == "禁用")
            {
                col_shashiliao_6.Visible = false;
            }
            if (KeaoUtils.ConfigGetNodeAttr("沙石料7", "状态") == "禁用")
            {
                col_shashiliao_7.Visible = false;
            }
            if (KeaoUtils.ConfigGetNodeAttr("沙石料8", "状态") == "禁用")
            {
                col_shashiliao_8.Visible = false;
            }

            if (KeaoUtils.ConfigGetNodeAttr("粉料1", "状态") == "禁用")
            {
                col_fenliao_1.Visible = false;
            }
            if (KeaoUtils.ConfigGetNodeAttr("粉料2", "状态") == "禁用")
            {
                col_fenliao_2.Visible = false;
            }
            if (KeaoUtils.ConfigGetNodeAttr("粉料3", "状态") == "禁用")
            {
                col_fenliao_3.Visible = false;
            }
            if (KeaoUtils.ConfigGetNodeAttr("粉料4", "状态") == "禁用")
            {
                col_fenliao_4.Visible = false;
            }
            if (KeaoUtils.ConfigGetNodeAttr("粉料5", "状态") == "禁用")
            {
                col_fenliao_5.Visible = false;
            }
            if (KeaoUtils.ConfigGetNodeAttr("粉料6", "状态") == "禁用")
            {
                col_fenliao_6.Visible = false;
            }
            if (KeaoUtils.ConfigGetNodeAttr("粉料7", "状态") == "禁用")
            {
                col_fenliao_7.Visible = false;
            }
            if (KeaoUtils.ConfigGetNodeAttr("粉料8", "状态") == "禁用")
            {
                col_fenliao_8.Visible = false;
            }

            if (KeaoUtils.ConfigGetNodeAttr("外加剂1", "状态") == "禁用")
            {
                col_waijiaji_1.Visible = false;
            }
            if (KeaoUtils.ConfigGetNodeAttr("外加剂2", "状态") == "禁用")
            {
                col_waijiaji_2.Visible = false;
            }
            if (KeaoUtils.ConfigGetNodeAttr("外加剂3", "状态") == "禁用")
            {
                col_waijiaji_3.Visible = false;
            }
            if (KeaoUtils.ConfigGetNodeAttr("外加剂4", "状态") == "禁用")
            {
                col_waijiaji_4.Visible = false;
            }
            if (KeaoUtils.ConfigGetNodeAttr("外加剂5", "状态") == "禁用")
            {
                col_waijiaji_5.Visible = false;
            }

            if (KeaoUtils.ConfigGetNodeAttr("水1", "状态") == "禁用")
            {
                col_shui_1.Visible = false;
            }
            if (KeaoUtils.ConfigGetNodeAttr("水2", "状态") == "禁用")
            {
                col_shui_2.Visible = false;
            }
        }

        private void btn_xinzeng_Click(object sender, EventArgs e)
        {
            HunNingTuJiHuaLiang jiHuaLiang = new HunNingTuJiHuaLiang();
            jiHuaLiang.ShowDialog();
            BindInfo();
        }

        private void btn_xiugai_Click(object sender, EventArgs e)
        {
            if (dataGridView1.SelectedRows.Count == 0)
            {
                return;
            }
            HunNingTuJiHuaLiang jiHuaLiang = new HunNingTuJiHuaLiang(dataGridView1.SelectedRows[0]);
            jiHuaLiang.ShowDialog();
            BindInfo();
        }

        private void btn_qiehuan_Click(object sender, EventArgs e)
        {
            if (dataGridView1.SelectedRows.Count == 0)
            {
                return;
            }
            m_CurrentRow = dataGridView1.SelectedRows[0];
            lb_mingcheng.Text =string.Format("{0}",dataGridView1.SelectedRows[0].Cells["mingcheng"].Value);
        }

        private void btn_shanchu_Click(object sender, EventArgs e)
        {
            if (dataGridView1.SelectedRows.Count == 0)
            {
                return;
            }
            if (KeaoUtils.ShowQuestionMessage("确定要删除该配置单吗？") == DialogResult.Yes)
            {
                TableRow delRow = new TableRow() { TableName="tbl_hunningtupeibi", ID = string.Format("{0}",dataGridView1.SelectedRows[0].Cells["col_id"].Value) };
                if (KeaoUtils._DB.DeleteRowByID(delRow) > 0)
                {
                    KeaoUtils.ShowInfoMessage("删除数据成功。");
                    BindInfo();
                }
            }
        }

        private void BindInfo()
        {
            DataTable Dt = KeaoUtils._DB.GetDataTableByCondition("tbl_hunningtupeibi");
            dataGridView1.DataSource = Dt;
        }
    }
}
